import React, {Component} from 'react';
import {Select} from "antd";
import {getChannels} from "../../../api/article";

class ChannelSelect extends Component {
  state = {
    channels: []
  }

  componentDidMount() {
    this.getChannels()
  }

  getChannels = async () => {
    const res = await getChannels()
    console.log(res)
    this.setState({
      channels: res.data.channels
    })
  }

  render() {
    console.log(this.props)
    return (
      <div>
        <Select
          placeholder={'请选择频道'}
          value={this.props.value}
          onChange={this.props.onChange}
        >
          {
            this.state.channels.map(item => (
              <Select.Option
                value={item.id}
                key={item.id}
              >{item.name}</Select.Option>
            ))
          }
        </Select>
      </div>
    );
  }
}

export default ChannelSelect;
